package com.kedi.archivescenter.service.impl;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.kedi.archivescenter.service.PcVolunteerService;
import com.kedi.archivescenter.write.dao.mapper.PcVolunteerMapper;

/**
 * 
 *
 * @ClassName PcVolunteerService
 * @author: 陈辽逊
 * @date: 2019/7/17 11:32
 */
@Service
public class PcVolunteerServiceImpl implements PcVolunteerService {

	@Autowired
	public PcVolunteerMapper mapper;

	final static Logger logger = LoggerFactory.getLogger(PcVolunteerServiceImpl.class);

	/**
	 * 返回一个数据对象
	 * 
	 * @return volunteerpart
	 */
	@Override
	public List<Map<String, Object>> volunteerpart() {
		try {
			List<Map<String, Object>> a = mapper.volunteerpart();
			return a;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("修改失败");
			return null;
		}
	}

	/**
	 * 返回一个数据对象
	 * 
	 * @param volunteerid
	 * @return volunteerall
	 */
	@Override
	public List<Map<String, Object>> volunteerall(int volunteerid) {
		try {
			List<Map<String, Object>> a = mapper.volunteerall(volunteerid);
			return a;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("修改失败");
			return null;
		}
	}

	/**
	 * 返回一个数据对象
	 * 
	 * @param map
	 * @return volunteer
	 */
	@Override
	public int volunteer(Map map) {
		try {
			int a = mapper.volunteer(map);
			return a;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("修改失败");
			return 0;
		}
	}

	/**
	 * 返回一个数据对象
	 * 
	 * @param map
	 * @return ivolunteer
	 */
	@Override
	public int ivolunteer(Map map) {
		try {
			int a = mapper.ivolunteer(map);
			return a;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("修改失败");
			return 0;
		}
	}

	/**
	 * 插入失败则事务回滚
	 * 
	 * @param map
	 * @return volunteerpictures
	 */
	@Override
	@Transactional(rollbackFor = Exception.class, transactionManager = "secondaryTransactionManager")
	public boolean volunteerpictures(Map map) {
		int a = mapper.imagesource(map);
		int b = mapper.volunteerapplicant(map);
		if (a == 1 && b == 1) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * 插入失败则事务回滚
	 * 
	 * @param map
	 * @return ivolunteerpictures
	 */
	@Override
	@Transactional(rollbackFor = Exception.class, transactionManager = "secondaryTransactionManager")
	public boolean ivolunteerpictures(Map map) {
		int a = mapper.iimagesource(map);
		int b = mapper.ivolunteerapplicant(map);
		if (a == 1 && b == 1) {
			return true;
		} else {
			return false;
		}
	}
}
